home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / object_sel2dupgroup.py < prev    next >
Text File  |  2009-08-31  |  2KB  |  85 lines

  1. #!BPY
  2.  
  3. """
  4. Name: 'Selection to DupliGroup'
  5. Blender: 243
  6. Group: 'Object'
  7. Tooltip: 'Turn the selection into a dupliGroup using the active objects transformation, objects are moved into a new scene'
  8. """
  9.  
  10. __bpydoc__=\
  11. '''
  12. '''
  13.  
  14. # ***** BEGIN GPL LICENSE BLOCK *****
  15. #
  16. # Script copyright (C) Campbell Barton
  17. #
  18. # This program is free software; you can redistribute it and/or
  19. # modify it under the terms of the GNU General Public License
  20. # as published by the Free Software Foundation; either version 2
  21. # of the License, or (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. # GNU General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU General Public License
  29. # along with this program; if not, write to the Free Software Foundation,
  30. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  31. #
  32. # ***** END GPL LICENCE BLOCK *****
  33. # --------------------------------------------------------------------------
  34.  
  35.  
  36. from Blender import *
  37.  
  38. def main():
  39.     scn = Scene.GetCurrent()
  40.     ob_act = scn.objects.active
  41.     
  42.     if not ob_act:
  43.         Draw.PupMenu('Error%t|No active object')
  44.     
  45.     dup_name = ob_act.name
  46.     
  47.     obsel = list(scn.objects.context)
  48.     
  49.     # Sanity check
  50.     for ob in obsel:
  51.         parent = ob.parent
  52.         if parent:
  53.             if not parent.sel or parent not in obsel:
  54.                 Draw.PupMenu('Error%t|Objects "'+ob.name+'" parent "'+parent.name+'" is not in the selection')
  55.                 return
  56.     
  57.     mat_act = ob_act.matrixWorld
  58.     
  59.     # new group
  60.     grp = Group.New(dup_name)
  61.     grp.objects = obsel
  62.     
  63.     # Create the new empty object to be the dupli
  64.     ob_dup = scn.objects.new('Empty')
  65.     ob_dup.setMatrix(mat_act)
  66.     ob_dup.name = dup_name + '_dup'
  67.     
  68.     ob_dup.enableDupGroup = True
  69.     ob_dup.DupGroup = grp
  70.     
  71.     scn_new = Scene.New(dup_name)
  72.     
  73.     # Transform the objects to remove the active objects matrix.
  74.     mat_act_inv = mat_act.copy().invert()
  75.     for ob in obsel:
  76.         if not ob.parent:
  77.             ob.setMatrix(ob.matrixWorld * mat_act_inv)
  78.         
  79.         scn_new.objects.link(ob)
  80.         scn.objects.unlink(ob)    
  81.  
  82.  
  83. if __name__ == '__main__':
  84.     main()
  85.